﻿#region usings
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using InsuranceAdjuster.Services;
using InsuranceAdjuster.Web.Models;
#endregion
namespace InsuranceAdjuster.OccasionallyConnected.Messages {
    public class GetClaimMessage : Message {
    
        public GetClaimMessage(Guid claimGuid) {
            this.ClaimGuid = claimGuid;
            this.CacheRules = MessageDataSource.CacheAndServer | MessageDataSource.FromServerOnlyIfNoCacheOption;
        }

        protected override void OnlineOperation() {
            MarkAsyncStarted();
            GetDataService().GetClaimById(claims => {
                    if (claims != null && claims.Count > 0)
                        ResponseEntities.Add("Claim", new MessageResult(Verb.Read, Origin.Server, claims[0]));

                    MarkAsyncFinished();
                }, ClaimGuid);
        }

        protected override List<MessageResult> OfflineOperation(IObjectStore objectStore) {
            var Output = new List<MessageResult>();

            if (objectStore.ContainsEntity(ClaimGuid))
                Output.Add(new MessageResult(Verb.Read, Origin.Cache, objectStore.GetEntity<Claim>(ClaimGuid)));

            return Output;
        }
        public Guid ClaimGuid {
            get { return GetMessageData<Guid>("ClaimGuid"); }
            set { SetMessageData<Guid>("ClaimGuid", value); }
        }
    }
}
